import 'package:eye_flutter_app/provider/cart.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class CartItem extends StatefulWidget {
  CartItem({Key? key}) : super(key: key);

  @override
  State<CartItem> createState() => _CartItemState();
}

class _CartItemState extends State<CartItem> {
  @override
  Widget build(BuildContext context) {
    var cartProvider = Provider.of<CartProvider>(context);
    return cartProvider.list.isNotEmpty
        ? Column(
            children: cartProvider.list
                .map((e) => ListTile(
                      title: Text(e),
                      trailing: InkWell(
                        child: Icon(Icons.delete),
                        onTap: () {
                          cartProvider.removeItem(e);
                        },
                      ),
                    ))
                .toList())
        : Text('');
  }
}
